package com.szgr.baoyin.activity;

import android.app.Dialog;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.provider.MediaStore;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.JsonHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import com.szgr.baoyin.MainActivity;
import com.szgr.baoyin.MyApplication;
import com.szgr.baoyin.R;
import com.szgr.baoyin.utils.Constant;
import com.szgr.baoyin.utils.DialogUtils;
import com.szgr.baoyin.utils.MyTool;
import com.szgr.baoyin.utils.RLog;
import com.szgr.baoyin.utils.ToastUtils;
import com.szgr.baoyin.volley_upload_file.MultiPartStack;
import com.szgr.baoyin.volley_upload_file.MultiPartStringRequest;

import org.apache.http.Header;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

/**
 * 资质提交
 */
public class AptitudeSubmitActivity extends BaseActivity {

    private Dialog dialog;
    private RequestQueue mSingleQueue;
    private Map<String, String> urls;
    private String name;
    private String attach;
    private int num;
    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case 56:
                    DialogUtils.hideLoadingDialog();
                    switch (attach) {
                        case "attach1":
                            tv_aptitude_01.setText("上传成功");
                            tv_aptitude_01.setTextColor(Color.RED);
                            urls.put("img1_path", (String) msg.obj);
                            break;
                        case "attach2":
                            tv_aptitude_02.setText("上传成功");
                            tv_aptitude_02.setTextColor(Color.RED);
                            urls.put("img2_path", (String) msg.obj);
                            break;
                        case "attach3":
                            tv_aptitude_03.setText("上传成功");
                            tv_aptitude_03.setTextColor(Color.RED);
                            urls.put("img3_path", (String) msg.obj);
                            break;
                        case "attach4":
                            tv_aptitude_04.setText("上传成功");
                            tv_aptitude_04.setTextColor(Color.RED);
                            urls.put("img4_path", (String) msg.obj);
                            break;
                        case "attach5":
                            tv_aptitude_05.setText("上传成功");
                            tv_aptitude_05.setTextColor(Color.RED);
                            urls.put("img5_path", (String) msg.obj);
                            break;
                        case "attach6":
                            tv_aptitude_06.setText("上传成功");
                            tv_aptitude_06.setTextColor(Color.RED);
                            urls.put("img6_path", (String) msg.obj);
                            break;
                        case "attach7":
                            tv_aptitude_07.setText("上传成功");
                            tv_aptitude_07.setTextColor(Color.RED);
                            urls.put("img7_path", (String) msg.obj);
                            break;
                        case "attach8":
                            tv_aptitude_08.setText("上传成功");
                            tv_aptitude_08.setTextColor(Color.RED);
                            urls.put("img8_path", (String) msg.obj);
                            break;
                        case "attach9":
                            tv_aptitude_09.setText("上传成功");
                            tv_aptitude_09.setTextColor(Color.RED);
                            urls.put("img9_path", (String) msg.obj);
                            break;
                        case "attach10":
                            tv_aptitude_10.setText("上传成功");
                            tv_aptitude_10.setTextColor(Color.RED);
                            urls.put("img10_path", (String) msg.obj);
                            break;
                        case "attach11":
                            tv_aptitude_11.setText("上传成功");
                            tv_aptitude_11.setTextColor(Color.RED);
                            urls.put("img11_path", (String) msg.obj);
                            break;
                        case "attach12":
                            tv_aptitude_12.setText("上传成功");
                            tv_aptitude_12.setTextColor(Color.RED);
                            urls.put("img12_path", (String) msg.obj);
                            break;
                        case "attach13":
                            tv_aptitude_13.setText("上传成功");
                            tv_aptitude_13.setTextColor(Color.RED);
                            urls.put("img13_path", (String) msg.obj);
                            break;
                        case "attach14":
                            tv_aptitude_14.setText("上传成功");
                            tv_aptitude_14.setTextColor(Color.RED);
                            urls.put("img14_path", (String) msg.obj);
                            break;
                        case "attach15":
                            tv_aptitude_15.setText("上传成功");
                            tv_aptitude_15.setTextColor(Color.RED);
                            urls.put("img15_path", (String) msg.obj);
                            break;
                        case "attach16":
                            tv_aptitude_16.setText("上传成功");
                            tv_aptitude_16.setTextColor(Color.RED);
                            urls.put("img16_path", (String) msg.obj);
                            break;
                        case "attach17":
                            tv_aptitude_17.setText("上传成功");
                            tv_aptitude_17.setTextColor(Color.RED);
                            urls.put("img17_path", (String) msg.obj);
                            break;
                        case "attach18":
                            tv_aptitude_18.setText("上传成功");
                            tv_aptitude_18.setTextColor(Color.RED);
                            urls.put("img18_path", (String) msg.obj);
                            break;
                    }
                    break;
                case 57:
                    DialogUtils.hideLoadingDialog();
                    ToastUtils.showToast("提交失败，图片可能过大");
                    break;
                case 666:
                    ToastUtils.showToast("提交成功，请耐心等待后台审核");
                    Intent intent = new Intent(AptitudeSubmitActivity.this, MainActivity.class);
                    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent);
                    finish();
                    break;
                case 667:
                    ToastUtils.showToast("提交失败，请完善审核资料");
                    break;
            }
        }
    };
    private TextView tv_aptitude_01;
    private TextView tv_aptitude_02;
    private TextView tv_aptitude_03;
    private TextView tv_aptitude_04;
    private TextView tv_aptitude_05;
    private TextView tv_aptitude_06;
    private TextView tv_aptitude_07;
    private TextView tv_aptitude_08;
    private TextView tv_aptitude_09;
    private TextView tv_aptitude_10;
    private TextView tv_aptitude_11;
    private TextView tv_aptitude_12;
    private TextView tv_aptitude_13;
    private TextView tv_aptitude_14;
    private TextView tv_aptitude_15;
    private TextView tv_aptitude_16;
    private TextView tv_aptitude_17;
    private TextView tv_aptitude_18;
    private TextView tv_currentText;
    private String imagePath;
    private String pay_sn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.activity_aptitude_submit);
        super.onCreate(savedInstanceState);
    }

    @Override
    public void initActionBar() {
        actionBarTitle.setText("资质提交");
    }

    @Override
    public void initView() {
        tv_aptitude_01 = (TextView) findViewById(R.id.aptitude_01);
        tv_aptitude_01.setOnClickListener(this);
        tv_aptitude_02 = (TextView) findViewById(R.id.aptitude_02);
        tv_aptitude_02.setOnClickListener(this);
        tv_aptitude_03 = (TextView) findViewById(R.id.aptitude_03);
        tv_aptitude_03.setOnClickListener(this);
        tv_aptitude_04 = (TextView) findViewById(R.id.aptitude_04);
        tv_aptitude_04.setOnClickListener(this);
        tv_aptitude_05 = (TextView) findViewById(R.id.aptitude_05);
        tv_aptitude_05.setOnClickListener(this);
        tv_aptitude_06 = (TextView) findViewById(R.id.aptitude_06);
        tv_aptitude_06.setOnClickListener(this);
        tv_aptitude_07 = (TextView) findViewById(R.id.aptitude_07);
        tv_aptitude_07.setOnClickListener(this);
        tv_aptitude_08 = (TextView) findViewById(R.id.aptitude_08);
        tv_aptitude_08.setOnClickListener(this);
        tv_aptitude_09 = (TextView) findViewById(R.id.aptitude_09);
        tv_aptitude_09.setOnClickListener(this);
        tv_aptitude_10 = (TextView) findViewById(R.id.aptitude_10);
        tv_aptitude_10.setOnClickListener(this);
        tv_aptitude_11 = (TextView) findViewById(R.id.aptitude_11);
        tv_aptitude_11.setOnClickListener(this);
        tv_aptitude_12 = (TextView) findViewById(R.id.aptitude_12);
        tv_aptitude_12.setOnClickListener(this);
        tv_aptitude_13 = (TextView) findViewById(R.id.aptitude_13);
        tv_aptitude_13.setOnClickListener(this);
        tv_aptitude_14 = (TextView) findViewById(R.id.aptitude_14);
        tv_aptitude_14.setOnClickListener(this);
        tv_aptitude_15 = (TextView) findViewById(R.id.aptitude_15);
        tv_aptitude_15.setOnClickListener(this);
        tv_aptitude_16 = (TextView) findViewById(R.id.aptitude_16);
        tv_aptitude_16.setOnClickListener(this);
        tv_aptitude_17 = (TextView) findViewById(R.id.aptitude_17);
        tv_aptitude_17.setOnClickListener(this);
        tv_aptitude_18 = (TextView) findViewById(R.id.aptitude_18);
        tv_aptitude_18.setOnClickListener(this);

        findViewById(R.id.submit_now).setOnClickListener(this);
        initDialog();
        findViewById(R.id.operator).setOnClickListener(this);

        mSingleQueue = Volley.newRequestQueue(this, new MultiPartStack());

        urls = new HashMap<>();

        Intent intent = getIntent();
        if (intent != null && intent.hasExtra("pay_sn")) {
            pay_sn = intent.getStringExtra("pay_sn");
        }
    }

    private void initDialog() {
        View view = LayoutInflater.from(this).inflate(R.layout.layout_my_account_dialog, null, false);
        view.findViewById(R.id.account_paizhao).setOnClickListener(this);
        view.findViewById(R.id.account_choose).setOnClickListener(this);
        view.findViewById(R.id.account_cancel).setOnClickListener(this);
        dialog = MyTool.getMenuDialog(this, view);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.action_bar_left:
                finish();
                break;
            case R.id.protect_buy_now:
                dialog.dismiss();
                break;
            case R.id.account_paizhao:
                dialog.dismiss();
                Intent intent1 = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                String savePath = MyTool.getSavePath(getApplicationContext());
                Uri imageUri = Uri.fromFile(new File(savePath, "image.jpg"));
                intent1.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
                startActivityForResult(intent1, 331);
                break;
            case R.id.account_choose:
                dialog.dismiss();
                Intent intent2 = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
//                intent2.setType("image/*");
//                intent2.setAction(Intent.ACTION_GET_CONTENT);
                startActivityForResult(intent2, 332);
                break;
            case R.id.account_cancel:
                dialog.dismiss();
                break;
            case R.id.submit_now:
//                submitAptitude();
//                for (Map<String, String> map : urls) {
//                    submitPic(map.get("attach"), map.get("name"), new File(map.get("goods_image")));
//                }
                if(pay_sn != null){
                    submitOrder();
                }
                break;
            case R.id.operator:
                startActivity(new Intent(this, FinanceOperatorActivity.class));
                break;
            case R.id.aptitude_01:
                attach = "attach1";
                name = "goods_image1";
//                Intent intent1 = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
//                startActivityForResult(intent1, 33);
                dialog.show();
                break;
            case R.id.aptitude_02:
                attach = "attach2";
                name = "goods_image2";
                dialog.show();
                break;
            case R.id.aptitude_03:
                attach = "attach3";
                name = "goods_image3";
                dialog.show();
                break;
            case R.id.aptitude_04:
                attach = "attach4";
                name = "goods_image4";
                dialog.show();
                break;
            case R.id.aptitude_05:
                attach = "attach5";
                name = "goods_image5";
                dialog.show();
                break;
            case R.id.aptitude_06:
                attach = "attach6";
                name = "goods_image6";
                dialog.show();
                break;
            case R.id.aptitude_07:
                attach = "attach7";
                name = "goods_image7";
                dialog.show();
                break;
            case R.id.aptitude_08:
                attach = "attach8";
                name = "goods_image8";
                dialog.show();
                break;
            case R.id.aptitude_09:
                attach = "attach9";
                name = "goods_image9";
                dialog.show();
                break;
            case R.id.aptitude_10:
                attach = "attach10";
                name = "goods_image10";
                dialog.show();
                break;
            case R.id.aptitude_11:
                attach = "attach11";
                name = "goods_image11";
                dialog.show();
                break;
            case R.id.aptitude_12:
                attach = "attach12";
                name = "goods_image12";
                dialog.show();
                break;
            case R.id.aptitude_13:
                attach = "attach13";
                name = "goods_image13";
                dialog.show();
                break;
            case R.id.aptitude_14:
                attach = "attach14";
                name = "goods_image14";
                dialog.show();
                break;
            case R.id.aptitude_15:
                attach = "attach15";
                name = "goods_image15";
                dialog.show();
                break;
            case R.id.aptitude_16:
                attach = "attach16";
                name = "goods_image16";
                dialog.show();
                break;
            case R.id.aptitude_17:
                attach = "attach17";
                name = "goods_image17";
                dialog.show();
                break;
            case R.id.aptitude_18:
                attach = "attach18";
                name = "goods_image18";
                dialog.show();
                break;
        }
    }

    private void submitOrder() {
        StringRequest sr = new StringRequest(Request.Method.POST, Constant.URL_RONGZI_DINGDAN,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String s) {
                        RLog.s("---order--->" + s);
                        try {
                            JSONObject jsonObject = new JSONObject(s);
                            JSONObject datas = jsonObject.getJSONObject("datas");
                            JSONObject result = datas.getJSONObject("result");
                            boolean success = result.getBoolean("success");
                            if(success){
                                mHandler.obtainMessage(666).sendToTarget();
                            }else{
                                mHandler.obtainMessage(667).sendToTarget();
                            }
                        } catch (JSONException e) {
                            mHandler.obtainMessage(667).sendToTarget();
                            e.printStackTrace();
                        }
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {

            }
        }){
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                Map<String,String> map = new HashMap<>();
                map.put("key",MyApplication.getmInstance().getKey());
                for (String str : urls.keySet()) {
                    map.put(str,urls.get(str));
                }
                map.put("pay_sn",pay_sn);
                return map;
            }
        };
        MyApplication.getmInstance().addToRequestQueue(sr);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        switch (requestCode) {
//            case 33:
//                if(data != null){
//                    Uri selectedUrl = data.getData();
//                    Cursor cursor = getContentResolver().query(selectedUrl, null, null, null, null);
//                    if (cursor == null) {
//                        ToastUtils.showToast("图片无效");
//                    } else {
//                        cursor.moveToFirst();
//                        String imagePath = cursor.getString(1);
//                        cursor.close();
//
//                    }
//                }
//                break;
//            case 34:
//                Bitmap data1 = BitmapFactory.decodeFile(MyTool.getSavePath(getApplicationContext()) + "/image.jpg");
//                String savePath = MyTool.getSavePath(getApplicationContext());
//                String picToSDCard = MyTool.savePicToSDCard(data1, savePath + "/BaoYin/");
//                System.out.println("---path--->" + picToSDCard);
//                break;
            case 332:
                if (resultCode == RESULT_OK) {
                    Uri selectedImage = data.getData();
                    Cursor cursor = getContentResolver().query(selectedImage, null, null, null, null);
                    if (cursor == null) {
                        ToastUtils.showToast("图片无效");
                    } else {
                        cursor.moveToFirst();
                        imagePath = cursor.getString(1);
//                            Bitmap bitmap = BitmapFactory.decodeFile(imagePath);
////                        img_head.setImageBitmap(bitmap);
//                            Bitmap bitmap1 = MyTool.getBitmapByBytes(MyTool.Bitmap2Bytes(bitmap), 900, 900);
//                            img_head.setImageBitmap(bitmap1);
                        cursor.close();
                    }
                    if (imagePath != null) {
                        switch (attach) {
                            case "attach1":
                                tv_aptitude_01.setText("已经选择");
                                tv_aptitude_01.setTextColor(Color.RED);
                                break;
                            case "attach2":
                                tv_aptitude_02.setText("已经选择");
                                tv_aptitude_02.setTextColor(Color.RED);
                                break;
                            case "attach3":
                                tv_aptitude_03.setText("已经选择");
                                tv_aptitude_03.setTextColor(Color.RED);
                                break;
                            case "attach4":
                                tv_aptitude_04.setText("已经选择");
                                tv_aptitude_04.setTextColor(Color.RED);
                                break;
                            case "attach5":
                                tv_aptitude_05.setText("已经选择");
                                tv_aptitude_05.setTextColor(Color.RED);
                                break;
                            case "attach6":
                                tv_aptitude_06.setText("已经选择");
                                tv_aptitude_06.setTextColor(Color.RED);
                                break;
                            case "attach7":
                                tv_aptitude_07.setText("已经选择");
                                tv_aptitude_07.setTextColor(Color.RED);
                                break;
                            case "attach8":
                                tv_aptitude_08.setText("已经选择");
                                tv_aptitude_08.setTextColor(Color.RED);
                                break;
                            case "attach9":
                                tv_aptitude_09.setText("已经选择");
                                tv_aptitude_09.setTextColor(Color.RED);
                                break;
                            case "attach10":
                                tv_aptitude_10.setText("已经选择");
                                tv_aptitude_10.setTextColor(Color.RED);
                                break;
                            case "attach11":
                                tv_aptitude_11.setText("已经选择");
                                tv_aptitude_11.setTextColor(Color.RED);
                                break;
                            case "attach12":
                                tv_aptitude_12.setText("已经选择");
                                tv_aptitude_12.setTextColor(Color.RED);
                                break;
                            case "attach13":
                                tv_aptitude_13.setText("已经选择");
                                tv_aptitude_13.setTextColor(Color.RED);
                                break;
                            case "attach14":
                                tv_aptitude_14.setText("已经选择");
                                tv_aptitude_14.setTextColor(Color.RED);
                                break;
                            case "attach15":
                                tv_aptitude_15.setText("已经选择");
                                tv_aptitude_15.setTextColor(Color.RED);
                                break;
                            case "attach16":
                                tv_aptitude_16.setText("已经选择");
                                tv_aptitude_16.setTextColor(Color.RED);
                                break;
                            case "attach17":
                                tv_aptitude_17.setText("已经选择");
                                tv_aptitude_17.setTextColor(Color.RED);
                                break;
                            case "attach18":
                                tv_aptitude_18.setText("已经选择");
                                tv_aptitude_18.setTextColor(Color.RED);
                                break;
                        }
                    }
//                    Map<String, String> map = new HashMap<>();
//                    map.put("name", name);
//                    map.put("attach", attach);
//                    map.put("goods_image", imagePath);
                    submitPic(attach, name, new File(imagePath));
                }
                break;
            case 331:
                if (resultCode == RESULT_OK) {
//                        Bitmap data1 = BitmapFactory.decodeFile(MyTool.getSavePath(getApplicationContext()) + "/image.jpg");
//                        String savePath = MyTool.getSavePath(getApplicationContext());
                    imagePath = MyTool.getSavePath(getApplicationContext()) + "/image.jpg";
//                    Bitmap bitmap = BitmapFactory.decodeFile(imagePath);
                    if (imagePath != null) {
                        switch (attach) {
                            case "attach1":
                                tv_aptitude_01.setText("已经选择");
                                tv_aptitude_01.setTextColor(Color.RED);
                                break;
                            case "attach2":
                                tv_aptitude_02.setText("已经选择");
                                tv_aptitude_02.setTextColor(Color.RED);
                                break;
                            case "attach3":
                                tv_aptitude_03.setText("已经选择");
                                tv_aptitude_03.setTextColor(Color.RED);
                                break;
                            case "attach4":
                                tv_aptitude_04.setText("已经选择");
                                tv_aptitude_04.setTextColor(Color.RED);
                                break;
                            case "attach5":
                                tv_aptitude_05.setText("已经选择");
                                tv_aptitude_05.setTextColor(Color.RED);
                                break;
                            case "attach6":
                                tv_aptitude_06.setText("已经选择");
                                tv_aptitude_06.setTextColor(Color.RED);
                                break;
                            case "attach7":
                                tv_aptitude_07.setText("已经选择");
                                tv_aptitude_07.setTextColor(Color.RED);
                                break;
                            case "attach8":
                                tv_aptitude_08.setText("已经选择");
                                tv_aptitude_08.setTextColor(Color.RED);
                                break;
                            case "attach9":
                                tv_aptitude_09.setText("已经选择");
                                tv_aptitude_09.setTextColor(Color.RED);
                                break;
                            case "attach10":
                                tv_aptitude_10.setText("已经选择");
                                tv_aptitude_10.setTextColor(Color.RED);
                                break;
                            case "attach11":
                                tv_aptitude_11.setText("已经选择");
                                tv_aptitude_11.setTextColor(Color.RED);
                                break;
                            case "attach12":
                                tv_aptitude_12.setText("已经选择");
                                tv_aptitude_12.setTextColor(Color.RED);
                                break;
                            case "attach13":
                                tv_aptitude_13.setText("已经选择");
                                tv_aptitude_13.setTextColor(Color.RED);
                                break;
                            case "attach14":
                                tv_aptitude_14.setText("已经选择");
                                tv_aptitude_14.setTextColor(Color.RED);
                                break;
                            case "attach15":
                                tv_aptitude_15.setText("已经选择");
                                tv_aptitude_15.setTextColor(Color.RED);
                                break;
                            case "attach16":
                                tv_aptitude_16.setText("已经选择");
                                tv_aptitude_16.setTextColor(Color.RED);
                                break;
                            case "attach17":
                                tv_aptitude_17.setText("已经选择");
                                tv_aptitude_17.setTextColor(Color.RED);
                                break;
                            case "attach18":
                                tv_aptitude_18.setText("已经选择");
                                tv_aptitude_18.setTextColor(Color.RED);
                                break;
                        }
                    }
//                    Map<String, String> map = new HashMap<>();
//                    map.put("name", name);
//                    map.put("attach", attach);
//                    map.put("goods_image", imagePath);
//                    urls.add(map);
                    submitPic(attach, name, new File(imagePath));
                }
                break;
        }
    }

    private void submitAptitude(final String attach, final String name, final File file) {
        MultiPartStringRequest mpsr = new MultiPartStringRequest(Request.Method.PUT, Constant.URL_FINANCE_SUBMIT,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String s) {
                        System.out.println("---submit--->" + s);
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {

            }
        }) {
            @Override
            public Map<String, File> getFileUploads() {
                Map<String, File> files = new HashMap<>();
                files.put(name, file);
                System.out.println("---files--->" + file.getAbsolutePath());
                return files;
            }

            @Override
            public Map<String, String> getStringUploads() {
                Map<String, String> params = new HashMap<>();
                params.put("attach", attach);
                params.put("name", name);
                params.put("key", MyApplication.getmInstance().getKey());
                System.out.println("---params--->" + params.toString());
                return params;
            }

            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                Map<String, String> params = new HashMap<>();
                params.put("attach", attach);
                params.put("name", name);
                params.put("key", MyApplication.getmInstance().getKey());
                System.out.println("---params--->" + params.toString());
                return params;
            }
        };
        mSingleQueue.add(mpsr);
    }

    private void submitPic(final String attach, final String name, final File file) {
        DialogUtils.showLoadingDialog(this, "正在上传中...", false);
        AsyncHttpClient client = new AsyncHttpClient();
        client.setTimeout(120 * 1000);
        RequestParams params = new RequestParams();
        params.put("attach", attach);
        params.put("name", name);
        params.put("key", MyApplication.getmInstance().getKey());
        try {
            params.put(name, file);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        RLog.s("----params-->" + file.getAbsolutePath());
        client.post(Constant.URL_FINANCE_SUBMIT, params, new JsonHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                if (response != null) {
                    if (response.has("thumb_url") && response.has("thumb_name")) {
                        RLog.s("---result1--->" + response.toString());
                        String thumb_url = response.optString("thumb_name");
                        mHandler.obtainMessage(56, thumb_url).sendToTarget();
                    } else {
                        mHandler.obtainMessage(57).sendToTarget();
                    }
                }
            }

            @Override
            public void onFailure(int statusCode, Throwable e, JSONObject errorResponse) {
                mHandler.obtainMessage(57).sendToTarget();
            }
        });
    }
}
